import java.util.ArrayList;
import java.util.Scanner;
import java.util.Stack;

/**
 * @Author Weton Li
 * @Date 2021/4/14 18:48
 */
public class Main {

    public static void main(String[] args) {
        Main main = new Main();
        String s = "(u(love)i)";
        System.out.println(main.method(s));

//        Scanner scanner = new Scanner(System.in);
//        String input = scanner.nextLine();
//        System.out.println(main.method(input));

    }

    public String method(String s) {

//        LinkedList<String> stack = new LinkedList<>();
        Stack<Character> stack = new Stack<>();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) != ')') {
                stack.push(s.charAt(i));
            } else {
                ArrayList<Character> list = new ArrayList<>();

                while (true) {
                    Character pop = stack.pop();
                    if (pop == '(') {
                        break;
                    }
                    list.add(pop);
                }
                for (Character character : list) {
                    stack.push(character);
                }
            }
        }
        while (!stack.isEmpty()) {
            sb.append(stack.pop());
        }
        return sb.reverse().toString();
    }
}
